package com.ruoze.bdp.function;

import com.ruoze.bdp.enums.DbType;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class DataSourceFunctionBeanFactory {

    @Autowired
    private Map<String, DataSourceFunction> dataSourceFunctionMap;

    public DataSourceFunction getDataSourceFunction(String type) {
        for (DataSourceFunction function: dataSourceFunctionMap.values()) {
            DbType sourceType = function.getSourceType();
            if (StringUtils.equalsAnyIgnoreCase(sourceType.getDesc(), type)) {
                return function;
            }
        }
        throw new IllegalArgumentException("illegal datasource type");
    }

}
